﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using AmiCheckin.Code.Util;
using AmiCheckin.Lib.Model;
using PropertyChanged;

namespace AmiCheckin.UI.ViewModels
{
    [AddINotifyPropertyChangedInterface]
    public class GlobalViewModel
    {
        public ObservableCollection<long> Masters { get; set; }
        public ObservableCollection<long> EnableGroups { get; set; }

        public bool GlobalMode { get; set; }
        public string SaveMode { get; set; }
        public string DefaultKeyword { get; set; }

        public void Load()
        {
            var config = ConfigUtil.GetConfig();

            Masters = new(config.Masters);
            EnableGroups = new(config.EnableGroups);
            GlobalMode = config.GlobalMode;
            SaveMode =  config.SaveMode.ToString();
            DefaultKeyword = config.DefaultKeyword;
        }

        public void Save()
        {
            var config = ConfigUtil.GetConfig();
             
            config.Masters=new(Masters);
            config.EnableGroups = new(EnableGroups);
            config.GlobalMode = GlobalMode;
            config.SaveMode = (LocationType)Enum.Parse(typeof(LocationType), SaveMode, true);
            config.DefaultKeyword = DefaultKeyword;

            ConfigUtil.SetConfig(config);
        }
    }
}